#pragma once
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>

/** deprecated!!! no need!*/
class OTexture2D {
public:
	static osg::Texture2D* install(int w, int h, bool hasAlphaChannel = false) {
		osg::Texture2D* texture = new osg::Texture2D;
		texture->setTextureSize(w, h);
		if (hasAlphaChannel) {
			texture->setInternalFormat(GL_RGBA8);
			texture->setSourceFormat(GL_RGBA);
		} else {
			texture->setInternalFormat(GL_RGB8);
			texture->setSourceFormat(GL_RGB);
		}
		texture->setSourceType(GL_UNSIGNED_BYTE);
		texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);// default
		texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);// default

		return texture;
	}

	static osg::Texture2D* createFromImage(osg::Image* image) {
		auto texture = new osg::Texture2D(image);
		texture->setResizeNonPowerOfTwoHint(false);
		return texture;
	}

	static osg::Texture2D* createFromImage(const std::string& imagePath) {
		auto image = osgDB::readImageFile(imagePath);
		auto texture = new osg::Texture2D(image);
		texture->setResizeNonPowerOfTwoHint(false);
		return texture;
	}
};